<?php
class CategroyTree {
	var $cato = array();
	var $cato_result = array();
	
	public function make_cato_tree(){
		
		$cato = d("Categroy_info");
		$result = $cato->select();
		
		foreach ($result as $key=>$value){
			$result2[$value['parent_id']] [$value['C_id']]= $value;
		}
		
		//dump($result2);
		$this->cato = $result2;
		$this->catotree();
		return $this->cato_result;
	}
	
	public function catotree($id = 0, $depth = 1) {
	       
	        if (empty($this->cato[$id])) return;
	        foreach ($this->cato[$id] AS $key => $class) {
        		$this->cato_result[]= array("C_id"=>$class['C_id'],"C_name"=>$class['C_name'],"parent_id"=>$class['parent_id'],"C_str"=>str_repeat("┣━", $depth), "C_depth"=>$class['C_depth']);
        		$this->catotree($key, $depth +1);
	        }
	        //如果一个文件要同时调用genOption两次,请注释下面一行.
	        unset ($this->cato[$id]);
	}
	
	
}



?>